import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { BaseService } from '@wwjCommon/base/base.service';
import { CacheService } from '@wwjCommon/cache/cache.service';
import { LoggingService } from '@wwjCommon/logging/logging.service';
import { UploadService } from '@wwjVendor/upload/upload.service';
import { PayService } from '@wwjVendor/pay/pay.service';
import { SmsService } from '@wwjVendor/sms/sms.service';
import { NoticeService } from '@wwjVendor/notice/notice.service';

@Injectable()
export class CoreBase64Service extends BaseService<any> {
  private readonly logger = new Logger(CoreBase64Service.name);

  constructor(
    @InjectRepository(Object)
    protected readonly repository: Repository<any>,
    private readonly cacheService: CacheService,
    private readonly configService: ConfigService,
    private readonly loggingService: LoggingService,
    private readonly uploadService: UploadService,
    private readonly payService: PayService,
    private readonly smsService: SmsService,
    private readonly noticeService: NoticeService,
  ) {
    super(repository);
  }

  /**
   * image
   * 对应 PHP: CoreBase64Service_core::image()
   * 逻辑类型: undefined - undefined
   */
  async image(content: number, site_id: number, file_dir: number) {
    // 基于PHP真实逻辑: image
    // PHP原文: if (empty($content)) throw new UploadFileException('BASE_IMAGE_FILE_NOT_EXIST');         $this->upload_driver = $this->driver($site_id);         $file...
if (!content)) throw new UploadFileBusinessException('BASE_IMAGE_FILE_NOT_EXIST'];
        this.upload_driver = this.driver(site_id);
        const file_path = this.upload_driver.createFileName(time(), 'jpg'];

        const dir = this.root_path  + '/' . file_dir  + '/' . file_path;
        const result = this.upload_driver.base64(content, dir);
        //读取上传附件的信息用于后续得校验和数据写入
        return [
            url: this.upload_driver.getUrl(dir)
        ;
  }
  }
}
